package Models;

import java.util.Calendar;
import java.util.Date;

/**
 * @author Morten
 */
public class Rental
{
	private static int nextId = 100;
	private int id;
	private Date rentalDate, expectedReturnDate, returnDate;
	private Machine machine;
	private Customer customer;
	private double deposit = 500d, pricePerDay = 50d, totalPrice;
	private boolean activated = true;

	public Rental(Machine machine, Customer customer, double deposit, double pricePerDay)
	{
		this.edit(Calendar.getInstance().getTime(), null, null, machine, customer, deposit, pricePerDay, 0);
		Calendar expectedReturnDateTemp = Calendar.getInstance();
		expectedReturnDateTemp.setTime(rentalDate);
		expectedReturnDateTemp.add(Calendar.DATE, 7);
		this.setExpectedReturnDate(expectedReturnDateTemp.getTime());
		this.machine.setAvailable(false);
		this.id = Rental.nextId;
		Rental.nextId++;
	}

	public double calculateTotalPrice()
	{
		//Afleveringstiden minus udlejningstiden, i millisekunder, divideret op til dage
		int days = (int)((this.returnDate.getTime()-this.rentalDate.getTime())/(1000*60*60*24));
		this.totalPrice = this.pricePerDay * days;
		this.totalPrice += this.deposit;
		return this.totalPrice;
	}

	public void edit(Date rentalDate, Date expectedReturnDate, Date returnDate, Machine machine, Customer customer, double deposit, double pricePerDay, double totalPrice)
	{
		this.setRentalDate(rentalDate);
		this.setExpectedReturnDate(expectedReturnDate);
		this.setReturnDate(returnDate);
		this.setMachine(machine);
        this.setCustomer(customer);
		this.setDeposit(deposit);
		this.setPricePerDay(pricePerDay);
		this.setTotalPrice(totalPrice);
	}

	public Customer getCustomer()
	{
		return customer;
	}

	public Date getExpectedReturnDate()
	{
		return expectedReturnDate;
	}

	public int getId()
	{
		return id;
	}

	public Machine getMachine()
	{
		return machine;
	}

	public Date getRentalDate()
	{
		return rentalDate;
	}

	public Date getReturnDate()
	{
		return returnDate;
	}

	public double getDeposit()
	{
		return deposit;
	}

	public double getPricePerDay()
	{
		return pricePerDay;
	}

	public double getTotalPrice()
	{
		return totalPrice;
	}

	public boolean isActivated()
	{
		return activated;
	}

	public void setActivated(boolean activated)
	{
		this.activated = activated;
	}

	public void setCustomer(Customer customer)
	{
		this.customer = customer;
	}

	public void setExpectedReturnDate(Date expectedReturnDate)
	{
		this.expectedReturnDate = expectedReturnDate;
	}

	public void setMachine(Machine machine)
	{
		this.machine = machine;
	}

	public void setRentalDate(Date rentalDate)
	{
		this.rentalDate = rentalDate;
	}

	public void setReturnDate(Date returnDate)
	{
		this.returnDate = returnDate;
	}

	public void setDeposit(double deposit)
	{
		this.deposit = deposit;
	}

	public void setPricePerDay(double pricePerDay)
	{
		this.pricePerDay = pricePerDay;
	}

	public void setTotalPrice(double totalPrice)
	{
		this.totalPrice = totalPrice;
	}
}
